<?php
/**
 * 园所后台左侧菜单model
 */
class Nursery_menu_model extends CT_Model
{
	public $_table = 'nursery_menu';
	public $_table_action = 'nursery_action';
	public $top_menus;
	public $top_permissions;
	
	public function __construct()
	{
		parent::__construct();
		$this->load->database();
		$this->top_menus=$this->get_menus();
		$this->top_permissions=$this->get_permissions();
	}

	/**
	 * 获取菜单表中已经录入的所有顶级菜单
	 * 返回值 一维数组 数组元素值 顶级菜单名称
	 * @return array
	 */
	public function get_menus($pid=0)
	{
		$this->db->select('id,name');
		$this->db->where("pid",$pid);
		$this->db->order_by('orderby', 'asc');
		$res=$this->db->get($this->_table)->result_array();
		$return=array();
		foreach($res as $val){
			$key=$val['id'];
			$return[$key]=$val["name"];
		}
		
		return $return;
	}

	/**
	 * 根据特定的父级菜单id获取该父级id下面的所有子菜单
	 * @param $pid
	 */

	public  function  get_child_menus($pid)
	{
		$this->db->select('*');
		$this->db->where("pid",$pid);
		$this->db->order_by('orderby', 'asc');
		$res=$this->db->get($this->_table)->result_array();
		return $res;
	}

	/**
	 * 获取权限表中已经录入的所有顶级权限
	 * 返回值 一维数组 数组元素值 顶级权限id
	 * @return array
	 */
	public  function  get_permissions($pid=0)
	{
		$this->db->select('id');
		$this->db->where("pid",$pid);
		$res=$this->db->get($this->_table_action)->result_array();
		$return=array();
		foreach($res as $key=>$val){
			$return[$key]=$val["id"];
		}
		return $return;
	}

	/**
	 * 根据特定的父级权限id获取该父级id下面的所有子权限
	 * @param $pid
	 */

	public  function  get_child_permissions($pid)
	{
		$this->db->select('*');
		$this->db->where("pid",$pid);
		$res=$this->db->get($this->_table_action)->result_array();
		return $res;
	}


}